﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UIT.Web.Controls.Html;
using UIT.Controls.Containers;
using UIT.Controls;

namespace UIT.Web.Renderers
{
	public abstract class HtmlControlRenderer<T> : WebControlRenderer<T>
		where T : HtmlControl
	{
		protected void RenderBeginTag(HtmlControl control)
		{
			writer.WriteStartElement(control.TagName);
			if (!string.IsNullOrEmpty(control.Id))
				writer.WriteAttributeString("id", control.Id);
		}

		protected void RenderEndTag(HtmlControl control)
		{
			if (control.NeedFullClosingTag)
				writer.WriteFullEndElement();
			else
				writer.WriteEndElement();
		}
	}

	public class HtmlControlRenderer : HtmlControlRenderer<HtmlControl>
	{
		public override void Render(HtmlControl control)
		{
			RenderBeginTag(control);
			if (control.IsContainer)
				base.Render((IContainer)control);
			RenderEndTag(control);
		}
	}
}
